package com.seckill.util;

/**
 * @Creation_time 2017/9/8
 * @Theme 用枚举类来表示常量数据字典(dto.SeckillExecution中的秒杀状态)
 * @Autor Xiao Yiyun
 */
public enum  SeckillStatusEnum {

    SUCCESS(1, "秒杀成功"),
    END(0, "秒杀结束"),
    REPEAT_KILL(-1, "重复秒杀"),
    INNER_ERROR(-2, "系统异常"),
    DATA_REWRITE(-3, "数据篡改");

    //定义数据常量类型
    private int status;
    private String statusInfo;

    //构造函数
    SeckillStatusEnum(int status, String statusInfo) {
        this.status = status;
        this.statusInfo = statusInfo;
    }

    //getter方法的到常量数据
    public int getStatus() {
        return status;
    }
    public String getStatusInfo() {
        return statusInfo;
    }

    //列举所有的结果可能值
    public static SeckillStatusEnum statusOf(int index) {
        for (SeckillStatusEnum statusEnum:values()) {
            if (statusEnum.getStatus() == index) {
                return statusEnum;
            }
        }
        return null;
    }
}
